/*
 *   cashMode="Cash And TwoPay";
 *
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaceNewOrder_Home.java
 *
 * Created on Oct 2, 2014, 4:03:29 PM
 */
package com.JD.PlaceOrder;

import com.JD.master.Validation.Validator;
import com.JD.placeNewOrder.Hibernate.Placeorder;
import java.awt.print.PrinterException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *
 * @author admin
 */
public class PlaceNewOrder_Home extends javax.swing.JFrame {

    /** Creates new form PlaceNewOrder_Home */
    com.JD.master.Validation.Validator validator = new Validator();

    public PlaceNewOrder_Home() {
        initComponents();

        payableAmount_TextField.setVisible(false);
        payableAmount_lable.setVisible(false);

        twoPayAmount_Lable.setVisible(false);
        twoPayAmount_TextField.setVisible(false);


        SessionFactory sessionFactory = com.JD.master.Hibernate.Master_HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();



        Query partyQuery = session.createQuery("from com.JD.master.Hibernate.PartyMaster");
        List partyList = partyQuery.list();

        partyName_ComboBox.removeAllItems();

        for (Object object : partyList) {

            com.JD.master.Hibernate.PartyMaster partyMaster = (com.JD.master.Hibernate.PartyMaster) object;

            partyName_ComboBox.addItem(partyMaster.getPartyName());


        }



        Query productQuery = session.createQuery("from com.JD.master.Hibernate.ProductMaster");
        List list = productQuery.list();

        particular_ComboBox.removeAllItems();

        for (Object object : list) {

            com.JD.master.Hibernate.ProductMaster productMaster = (com.JD.master.Hibernate.ProductMaster) object;

            particular_ComboBox.addItem(productMaster.getProductItem());

        }

        //com.JD.placeNewOrder.Hibernate.Placeorder

        Query q = session.createQuery("from com.JD.placeNewOrder.Hibernate.Placeorder");

        javax.swing.table.DefaultTableModel finalDataAdd_Table_Model = (javax.swing.table.DefaultTableModel) finalDataAdd_Table.getModel();



        List l = q.list();

        for (Object object : l) {

            com.JD.placeNewOrder.Hibernate.Placeorder placeorder = (com.JD.placeNewOrder.Hibernate.Placeorder) object;
            finalDataAdd_Table_Model.insertRow(0, new Object[]{placeorder.getSrNo(), placeorder.getPartyName(), placeorder.getDriverName(), placeorder.getRoyaltyNo(), placeorder.getVehicleNo(), placeorder.getDateOfOrder(), placeorder.getTimeOfOrder(), placeorder.getTotalAmount(), placeorder.getCashMode(), placeorder.getRawField1(), placeorder.getPayAbleAmount(), placeorder.getPrintingStatus()});



        }


        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        //get current date time with Date()
        Date date = new Date();

        date_Lable.setText(dateFormat.format(date));
        dateOfOrder = dateFormat.format(date);

        DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
        //get current date time with Date()
        Date time = new Date();

        time_Lable.setText(timeFormat.format(time));
        timeOfOrder = timeFormat.format(time);







    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    String partyName = "No";
    String particular = "";
    String measurement = "No";
    String driverName = "No";
    String royaltyNo = "No";
    String vehicleNo = "No";
    String dateOfOrder = "No";
    String timeOfOrder = "No";
    String srNo = "No";
    String totalAmount = "No";
    String cashMode = "No";
    String payAbleAmount = "NO";
    String driverPic = "NO";
    String printingStatus = "NO";
    String pendingStatus = "NO";
    //rawField represent twoPayAmount
    String rawField1 = "NO";
    //rawField represent twoPayAmount
    String rawField2 = "NO";
    String rawField3 = "NO";
    String rawField4 = "NO";
    long RawTotalAmount = 0;
    int list = 0;
    int flag = 0;
    int internalFlag = 0;

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        placeNewOrder_Panel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        partyName_ComboBox = new javax.swing.JComboBox();
        particular_ComboBox = new javax.swing.JComboBox();
        measurement_ComboBox = new javax.swing.JComboBox();
        driverName_TextField = new javax.swing.JTextField();
        royaltyNumber_TextField = new javax.swing.JTextField();
        vehicleNumber_TextField = new javax.swing.JTextField();
        totalAmount_TextField = new javax.swing.JTextField();
        cash_ChackBox = new javax.swing.JCheckBox();
        twoPay_ChackBox = new javax.swing.JCheckBox();
        cashAndTwoPay_ChackBox = new javax.swing.JCheckBox();
        payableAmount_lable = new javax.swing.JLabel();
        payableAmount_TextField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        orderList_Table = new javax.swing.JTable();
        jLabel11 = new javax.swing.JLabel();
        amount_TextField = new javax.swing.JTextField();
        AddDataToTable_Button = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        finalDataAdd_Table = new javax.swing.JTable();
        date_Lable = new javax.swing.JLabel();
        time_Lable = new javax.swing.JLabel();
        addDataToDatabase_Button = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        twoPayAmount_Lable = new javax.swing.JLabel();
        twoPayAmount_TextField = new javax.swing.JTextField();
        deleteItem_ComboBox = new javax.swing.JComboBox();
        deleteItem_Button = new javax.swing.JButton();
        exportToExcel = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        placeNewOrder_Panel.setBackground(new java.awt.Color(255, 102, 51));
        placeNewOrder_Panel.setPreferredSize(new java.awt.Dimension(1135, 627));

        jLabel1.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel1.setText("Party Name:");

        jLabel2.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel2.setText("Particular: ");

        jLabel3.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel3.setText("Measurement:  ");

        jLabel4.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel4.setText("Driver Name:  ");

        jLabel5.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel5.setText("Royalty Number: ");

        jLabel6.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel6.setText("Vehicle Number:");

        jLabel7.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel7.setText("Date: ");

        jLabel8.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel8.setText("Time: ");

        jLabel9.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel9.setText("Sr.No:");

        jLabel10.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel10.setText("Total Amount: ");

        partyName_ComboBox.setEditable(true);
        partyName_ComboBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        partyName_ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Party Name" }));

        particular_ComboBox.setEditable(true);
        particular_ComboBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        particular_ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Particular" }));

        measurement_ComboBox.setEditable(true);
        measurement_ComboBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        measurement_ComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "20mm", "40mm", "60mm", "80mm", "100mm" }));

        driverName_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        driverName_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                driverName_TextFieldKeyReleased(evt);
            }
        });

        royaltyNumber_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        royaltyNumber_TextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                royaltyNumber_TextFieldActionPerformed(evt);
            }
        });

        vehicleNumber_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));

        totalAmount_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        totalAmount_TextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                totalAmount_TextFieldActionPerformed(evt);
            }
        });
        totalAmount_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                totalAmount_TextFieldKeyReleased(evt);
            }
        });

        cash_ChackBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        cash_ChackBox.setText("Cash");
        cash_ChackBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cash_ChackBoxActionPerformed(evt);
            }
        });

        twoPay_ChackBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        twoPay_ChackBox.setText("Two Pay");
        twoPay_ChackBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                twoPay_ChackBoxActionPerformed(evt);
            }
        });

        cashAndTwoPay_ChackBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        cashAndTwoPay_ChackBox.setText("Cash And Two Pay");
        cashAndTwoPay_ChackBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cashAndTwoPay_ChackBoxActionPerformed(evt);
            }
        });

        payableAmount_lable.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        payableAmount_lable.setText("Payable Amount:");

        payableAmount_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        payableAmount_TextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                payableAmount_TextFieldActionPerformed(evt);
            }
        });
        payableAmount_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                payableAmount_TextFieldKeyReleased(evt);
            }
        });

        orderList_Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Sr.No", "Particular", "Measurement", "Amount"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(orderList_Table);

        jLabel11.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        jLabel11.setText("Amount :");

        amount_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        amount_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                amount_TextFieldKeyReleased(evt);
            }
        });

        AddDataToTable_Button.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        AddDataToTable_Button.setText("Add");
        AddDataToTable_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddDataToTable_ButtonActionPerformed(evt);
            }
        });

        finalDataAdd_Table.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Sr.No", "Party Name", "Driver Name", "Royalty Number", "Vehicle Number", "Date", "Time", "Total Amount", "Cash Mode", "Two Pay Amount", "Payable Amount", "Printing Status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(finalDataAdd_Table);
        finalDataAdd_Table.getColumnModel().getColumn(0).setMinWidth(45);
        finalDataAdd_Table.getColumnModel().getColumn(0).setPreferredWidth(40);
        finalDataAdd_Table.getColumnModel().getColumn(0).setMaxWidth(45);
        finalDataAdd_Table.getColumnModel().getColumn(1).setPreferredWidth(150);
        finalDataAdd_Table.getColumnModel().getColumn(2).setPreferredWidth(100);

        date_Lable.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        date_Lable.setText("ss");

        time_Lable.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        time_Lable.setText("jLabel13");

        addDataToDatabase_Button.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        addDataToDatabase_Button.setText("Add Data");
        addDataToDatabase_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDataToDatabase_ButtonActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        jLabel12.setText("6000");

        twoPayAmount_Lable.setFont(new java.awt.Font("Traditional Arabic", 1, 14));
        twoPayAmount_Lable.setText("TwoPay Amount:");

        twoPayAmount_TextField.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        twoPayAmount_TextField.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                twoPayAmount_TextFieldMouseEntered(evt);
            }
        });
        twoPayAmount_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                twoPayAmount_TextFieldKeyReleased(evt);
            }
        });

        deleteItem_ComboBox.setFont(new java.awt.Font("Traditional Arabic", 0, 14));

        deleteItem_Button.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        deleteItem_Button.setText("Delete Item");
        deleteItem_Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteItem_ButtonActionPerformed(evt);
            }
        });

        exportToExcel.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
        exportToExcel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/JD/PlaceOrder/excel.png"))); // NOI18N
        exportToExcel.setText("Export To Excel");
        exportToExcel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportToExcelActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Traditional Arabic", 1, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/JD/PlaceOrder/print.png"))); // NOI18N
        jButton1.setText("Print");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout placeNewOrder_PanelLayout = new javax.swing.GroupLayout(placeNewOrder_Panel);
        placeNewOrder_Panel.setLayout(placeNewOrder_PanelLayout);
        placeNewOrder_PanelLayout.setHorizontalGroup(
            placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 1016, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, placeNewOrder_PanelLayout.createSequentialGroup()
                                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                        .addComponent(particular_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel3))
                                    .addComponent(partyName_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(measurement_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                        .addGap(4, 4, 4)
                                        .addComponent(amount_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(AddDataToTable_Button))
                                    .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                        .addGap(208, 208, 208)
                                        .addComponent(jLabel9)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel12)))
                                .addGap(505, 505, 505))
                            .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel6)
                                .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                    .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                            .addComponent(cash_ChackBox)
                                            .addGap(30, 30, 30)
                                            .addComponent(twoPay_ChackBox))
                                        .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                            .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(payableAmount_lable)
                                                .addComponent(jLabel4)
                                                .addComponent(jLabel7))
                                            .addGap(32, 32, 32)
                                            .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                                    .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(addDataToDatabase_Button)
                                                        .addComponent(date_Lable, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGap(18, 18, 18)
                                                    .addComponent(jLabel8)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(time_Lable, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addComponent(payableAmount_TextField, javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(driverName_TextField, javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(vehicleNumber_TextField, javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(royaltyNumber_TextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)
                                                    .addComponent(cashAndTwoPay_ChackBox))))
                                        .addComponent(jLabel5))
                                    .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                            .addGap(42, 42, 42)
                                            .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel10)
                                                .addComponent(twoPayAmount_Lable))
                                            .addGap(18, 18, 18)
                                            .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                                    .addComponent(deleteItem_ComboBox, 0, 69, Short.MAX_VALUE)
                                                    .addGap(18, 18, 18)
                                                    .addComponent(deleteItem_Button))
                                                .addComponent(twoPayAmount_TextField, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)
                                                .addComponent(totalAmount_TextField, javax.swing.GroupLayout.Alignment.LEADING)))
                                        .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                                            .addGap(137, 137, 137)
                                            .addComponent(exportToExcel)
                                            .addGap(47, 47, 47)
                                            .addComponent(jButton1))))
                                .addComponent(jScrollPane1)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        placeNewOrder_PanelLayout.setVerticalGroup(
            placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(placeNewOrder_PanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(partyName_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(particular_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(measurement_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(amount_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(AddDataToTable_Button))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cash_ChackBox)
                    .addComponent(twoPay_ChackBox)
                    .addComponent(totalAmount_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cashAndTwoPay_ChackBox))
                .addGap(18, 18, 18)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(payableAmount_lable)
                    .addComponent(payableAmount_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(twoPayAmount_Lable)
                    .addComponent(twoPayAmount_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(driverName_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(royaltyNumber_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteItem_Button)
                    .addComponent(deleteItem_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(vehicleNumber_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(date_Lable)
                        .addComponent(jLabel8)
                        .addComponent(time_Lable)))
                .addGap(18, 18, 18)
                .addGroup(placeNewOrder_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addDataToDatabase_Button)
                    .addComponent(exportToExcel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(placeNewOrder_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, 1046, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(149, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(placeNewOrder_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, 718, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cashAndTwoPay_ChackBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cashAndTwoPay_ChackBoxActionPerformed
        // TODO add your handling code here:

        flag = 0;
        internalFlag = 1;

        cashMode = "Cash And TwoPay";

        payableAmount_TextField.setText("");
        twoPay_ChackBox.setSelected(false);
        cash_ChackBox.setSelected(false);
        payableAmount_TextField.setVisible(true);
        payableAmount_lable.setVisible(true);

        twoPayAmount_Lable.setVisible(true);
        twoPayAmount_TextField.setVisible(true);


}//GEN-LAST:event_cashAndTwoPay_ChackBoxActionPerformed

    private void twoPay_ChackBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twoPay_ChackBoxActionPerformed
        // TODO add your handling code here:

        flag = 0;
        internalFlag = 1;
        cashMode = "twoPay";
        cash_ChackBox.setSelected(false);
        cashAndTwoPay_ChackBox.setSelected(false);

        payableAmount_TextField.setVisible(false);
        payableAmount_lable.setVisible(false);
}//GEN-LAST:event_twoPay_ChackBoxActionPerformed

    private void cash_ChackBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cash_ChackBoxActionPerformed
        // TODO add your handling code here:

        flag = 1;

        internalFlag = 0;
        cashMode = "cash";

        payableAmount_TextField.setText(totalAmount_TextField.getText());

        twoPay_ChackBox.setSelected(false);
        cashAndTwoPay_ChackBox.setSelected(false);

        payableAmount_TextField.setVisible(true);
        payableAmount_lable.setVisible(true);


    }//GEN-LAST:event_cash_ChackBoxActionPerformed

    private void payableAmount_TextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_payableAmount_TextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_payableAmount_TextFieldActionPerformed

    private void totalAmount_TextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_totalAmount_TextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_totalAmount_TextFieldActionPerformed

    private void royaltyNumber_TextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_royaltyNumber_TextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_royaltyNumber_TextFieldActionPerformed
    javax.swing.table.DefaultTableModel orderList_Table_Model;
    int rowCountFromOrderListTable = 0;
    String testTemp = "";

    private void AddDataToTable_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddDataToTable_ButtonActionPerformed
        //  .getSelectedItem().toString();  TODO add your handling code here:

        particular = particular + "#" + particular_ComboBox.getSelectedItem().toString();
        measurement = measurement + "#" + measurement_ComboBox.getSelectedItem().toString();

        RawTotalAmount = RawTotalAmount + Integer.parseInt(amount_TextField.getText());
        totalAmount_TextField.setText(RawTotalAmount + "");

        //orderList_Table

        orderList_Table_Model = (javax.swing.table.DefaultTableModel) orderList_Table.getModel();

        orderList_Table_Model.insertRow(orderList_Table_Model.getRowCount(), new Object[]{orderList_Table_Model.getRowCount() + 1, particular_ComboBox.getSelectedItem().toString(), measurement_ComboBox.getSelectedItem().toString(), amount_TextField.getText()});

        amount_TextField.setText("");

        rowCountFromOrderListTable = rowCountFromOrderListTable + 1;

        testTemp = testTemp + orderList_Table_Model.getRowCount() + " ";

        deleteItem_ComboBox.addItem(orderList_Table_Model.getRowCount() + "");




    }//GEN-LAST:event_AddDataToTable_ButtonActionPerformed

    private void amount_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_amount_TextFieldKeyReleased
        // TODO add your handling code here:
        amount_TextField.setText(validator.numberValidator(amount_TextField.getText()));
    }//GEN-LAST:event_amount_TextFieldKeyReleased

    private void driverName_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_driverName_TextFieldKeyReleased
        // TODO add your handling code here:

        driverName_TextField.setText(validator.stringValidator(driverName_TextField.getText()).toUpperCase());
    }//GEN-LAST:event_driverName_TextFieldKeyReleased

    private void payableAmount_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_payableAmount_TextFieldKeyReleased
        // TODO add your handling code here:

        payableAmount_TextField.setText(validator.numberValidator(payableAmount_TextField.getText()));
    }//GEN-LAST:event_payableAmount_TextFieldKeyReleased

    private void totalAmount_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_totalAmount_TextFieldKeyReleased
        // TODO add your handling code here:

        totalAmount_TextField.setText(validator.numberValidator(totalAmount_TextField.getText()));

    }//GEN-LAST:event_totalAmount_TextFieldKeyReleased

    private void twoPayAmount_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_twoPayAmount_TextFieldKeyReleased
        // TODO add your handling code here:

        twoPayAmount_TextField.setText(validator.numberValidator(twoPayAmount_TextField.getText()));


    }//GEN-LAST:event_twoPayAmount_TextFieldKeyReleased

    private void twoPayAmount_TextFieldMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_twoPayAmount_TextFieldMouseEntered
        // TODO add your handling code here:

        int temp = Integer.parseInt(payableAmount_TextField.getText());


        int twoPayAmount = Integer.parseInt(totalAmount_TextField.getText()) - temp;

        twoPayAmount_TextField.setText(twoPayAmount + "");

        rawField1 = twoPayAmount + "";


    }//GEN-LAST:event_twoPayAmount_TextFieldMouseEntered

    private void addDataToDatabase_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDataToDatabase_ButtonActionPerformed
        // TODO add your handling code here:




        if (flag == 1 && totalAmount_TextField.getText().equals(payableAmount_TextField.getText())) {


            internalFlag = 1;

        }



        if (internalFlag == 1) {


            partyName = partyName_ComboBox.getSelectedItem().toString();


            driverName = driverName_TextField.getText();
            royaltyNo = royaltyNumber_TextField.getText();
            vehicleNo = vehicleNumber_TextField.getText();

            srNo = "6000";
            totalAmount = RawTotalAmount + "";

            payAbleAmount = payableAmount_TextField.getText();
            driverPic = "NO";
            printingStatus = "NO";
            pendingStatus = "NO";

            SessionFactory sessionFactory = com.JD.placeNewOrder.Hibernate.placeNewOrder_HibernateUtil.getSessionFactory();
            Session session = sessionFactory.openSession();
            Transaction transaction = session.beginTransaction();

            com.JD.placeNewOrder.Hibernate.Placeorder placeorder = new Placeorder(partyName, particular, measurement, driverName, royaltyNo, vehicleNo, dateOfOrder, timeOfOrder, srNo, totalAmount, cashMode, payAbleAmount, driverPic, printingStatus, pendingStatus, rawField1, rawField2, rawField3, rawField4);

            session.save(placeorder);
            transaction.commit();

            //finalDataAdd_Table

            javax.swing.table.DefaultTableModel finalDataAdd_Table_Model = (javax.swing.table.DefaultTableModel) finalDataAdd_Table.getModel();

            finalDataAdd_Table_Model.insertRow(0, new Object[]{srNo, partyName, driverName, royaltyNo, vehicleNo, dateOfOrder, timeOfOrder, totalAmount, cashMode, rawField1, payAbleAmount, printingStatus});





            for (int i = orderList_Table_Model.getRowCount() - 1; i >= 0; i--) {
                orderList_Table_Model.removeRow(i);
            }

            deleteItem_ComboBox.removeAllItems();










//
//     driverName_TextField.setText("");
//     royaltyNo = royaltyNumber_TextField.setText("");
//     vehicleNo = ;
//     dateOfOrder = ;
//     timeOfOrder = ;
//     srNo = ;
//     totalAmount = ;
//     cashMode = ;
//     payAbleAmount = ;
//     driverPic = ;
//     printingStatus = ;
//     pendingStatus = ;
//
//    //rawField represent twoPayAmount
//     rawField1 = ;
//    //rawField represent twoPayAmount

            totalAmount_TextField.setText("");
            twoPayAmount_TextField.setText("");
            payableAmount_TextField.setText("");
            driverName_TextField.setText("");
            royaltyNumber_TextField.setText("");
            vehicleNumber_TextField.setText("");


        } else {

            JOptionPane.showMessageDialog(null, "Please Change Cash Mode");

        }






    }//GEN-LAST:event_addDataToDatabase_ButtonActionPerformed

    private void deleteItem_ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteItem_ButtonActionPerformed
        // TODO add your handling code here:

        orderList_Table_Model.removeRow(Integer.parseInt(deleteItem_ComboBox.getSelectedItem().toString()) - 1);

        //  orderList_Table_Model.removeRow(1);


    }//GEN-LAST:event_deleteItem_ButtonActionPerformed

    private void exportToExcelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportToExcelActionPerformed
        // TODO add your handling code here:

        new  com.JD.ExportToExcel.ExportToExcel().saveToExcel(finalDataAdd_Table);
    }//GEN-LAST:event_exportToExcelActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
            finalDataAdd_Table.print();
        } catch (PrinterException ex) {
            JOptionPane.showMessageDialog(null, "Please Cheack Your Printer..");
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddDataToTable_Button;
    private javax.swing.JButton addDataToDatabase_Button;
    private javax.swing.JTextField amount_TextField;
    private javax.swing.JCheckBox cashAndTwoPay_ChackBox;
    private javax.swing.JCheckBox cash_ChackBox;
    private javax.swing.JLabel date_Lable;
    private javax.swing.JButton deleteItem_Button;
    private javax.swing.JComboBox deleteItem_ComboBox;
    private javax.swing.JTextField driverName_TextField;
    private javax.swing.JButton exportToExcel;
    private javax.swing.JTable finalDataAdd_Table;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox measurement_ComboBox;
    private javax.swing.JTable orderList_Table;
    private javax.swing.JComboBox particular_ComboBox;
    private javax.swing.JComboBox partyName_ComboBox;
    private javax.swing.JTextField payableAmount_TextField;
    private javax.swing.JLabel payableAmount_lable;
    public javax.swing.JPanel placeNewOrder_Panel;
    private javax.swing.JTextField royaltyNumber_TextField;
    private javax.swing.JLabel time_Lable;
    private javax.swing.JTextField totalAmount_TextField;
    private javax.swing.JLabel twoPayAmount_Lable;
    private javax.swing.JTextField twoPayAmount_TextField;
    private javax.swing.JCheckBox twoPay_ChackBox;
    private javax.swing.JTextField vehicleNumber_TextField;
    // End of variables declaration//GEN-END:variables

    public JPanel getPlaceNewOrder_Panel() {
        return placeNewOrder_Panel;
    }
}
